<?php
/**
 * @user: leo
 * @date: 2021/5/17
 * @createTime: 14:37
 * @company: 迈酷网络科技 http://www.maicooit.com
 */
namespace app\admin\model;

use think\Model;

class User extends Model
{
    //用户注册
    public function UserRegModel($domain,$user_name,$password){
        $UserInfo['domain'] = $domain;
        $UserInfo['user_name'] = $user_name;
        $UserInfo['password'] = $password;
        return $this->insertGetId($UserInfo);
    }
    //用户登录
    public function UserLoginModel($domain,$user_name,$password){
        $userinfo = $this->field('user_id,domain,user_name,status')
                         ->where('domain','=',$domain)
                         ->where('user_name','=',$user_name)
                         ->where('password','=',$password)
                         ->find();
        if($userinfo['status'] == 1){
            return $userinfo;
        }else{
            return false;
        }
    }
    //列表
    public function UserListModel($key,$domain,$page,$pagesize){
        $field = ['u.user_id','u.domain','u.user_name','u.status','ud.nickname','ud.sex','ud.birthday','ud.phone','ud.reg_ip','ud.reg_time','ud.last_login_ip','ud.last_login_time'];
        $list = $this->alias('u')
            ->where('domain','=',$domain)
            ->field($field)
            ->leftjoin('user_data ud','u.user_id = ud.user_id')
            ->paginate([
                'list_rows'=> $pagesize,
                'var_page' => 'page',
                'page'=>$page
            ]);
        return $list;
    }
    //新增
    public function UserInsertModel($UserInfo){
        return $this->insertGetId($UserInfo);
    }
    //保存
    public function UserSaveModel($userid,$userInfo){
        $where[] = ['user_id','=',$userid];
        $res = $this->where($where)->save($userInfo);
        return $res;
    }
    //启用、禁用
    public function UserDisableEableModel($userid){
        $where[] = ['user_id','=',$userid];
        $data['status'] = -1;
        $res = $this->where($where)->save($data);
        return $res;
    }
    //删除
    public function UserdelModel($userid){
        $where[] = ['user_id','=',$userid];
        $res = $this->where($where)->delete();
        return $res;
    }
}
